package com.gly091020.MaidCode.mixin;

import com.github.tartaricacid.touhoulittlemaid.ai.service.llm.openai.LLMOpenAIClient;
import com.gly091020.MaidCode.MaidCode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.net.http.HttpRequest;
import java.time.Duration;

@Mixin(LLMOpenAIClient.class)
public class TimeOutMixin {
    @Redirect(method = "chat", at = @At(value = "INVOKE", target = "Ljava/net/http/HttpRequest$Builder;timeout(Ljava/time/Duration;)Ljava/net/http/HttpRequest$Builder;"))
    private HttpRequest.Builder overwriteTimeOut(HttpRequest.Builder instance, Duration duration){
        // 60秒对于写代码还是不够用呢
        return instance.timeout(Duration.ofSeconds(MaidCode.CONFIG.chatTimeOut));
    }
}
